//
//  HomeSouceView.m
//  Fireball
//
//  Created by 俞渊华 on 2017/12/4.
//  Copyright © 2017年 俞渊华. All rights reserved.
//

#import "HomeSouceView.h"

@interface HomeSouceView ()
@property(nonatomic, strong)UILabel *timeLabel;
@property(nonatomic, strong)UILabel *souceLabel;
@property(nonatomic, strong)XMLabel *tagLabel;
@property(nonatomic, strong)UIButton* prioritybutton;
@end

@implementation HomeSouceView

-(instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        self.timeLabel = [[UILabel alloc]init];
        self.timeLabel.textColor = [UIColor xm_colorFromRGB:0x858C96];
        self.timeLabel.font = [UIFont xm_font:13.0];
//        [self addSubview:self.timeLabel];
        self.prioritybutton=[[UIButton alloc] init];
        [self.prioritybutton setBackgroundColor:DGColor];
        [self.prioritybutton setTitle:@"优先级高" forState:UIControlStateNormal];
        self.prioritybutton.titleLabel.font=[UIFont xm_font:13.0];
        self.prioritybutton.layer.cornerRadius=10;
        [self addSubview:self.prioritybutton];
        
        self.souceLabel = [[UILabel alloc]init];
        self.souceLabel.textColor = [UIColor xm_colorFromRGB:0x858C96];
        self.souceLabel.font = [UIFont xm_font:13.0];
        self.souceLabel.textAlignment=NSTextAlignmentCenter;
        [self addSubview:self.souceLabel];
        
        self.tagLabel = [[XMLabel alloc]init];
        self.tagLabel.layer.masksToBounds = YES;
        self.tagLabel.layer.cornerRadius = 8.0;
        self.tagLabel.font = [UIFont xm_font:10.0];
        self.tagLabel.edgeInsets = UIEdgeInsetsMake(3, 10, 3, 10);
        [self addSubview:self.tagLabel];
        
        
    }
    return self;
}
-(void)setModel:(WorkOrderModel *)model{
    _model = model;
    //    self.timeLabel.text = _model.UpdateTime;
    self.timeLabel.text = @"优先级高";
    self.souceLabel.text = @"待审批";
    if (_model.priority==2) {
        [self.prioritybutton setBackgroundColor:DGColor];
        [self.prioritybutton setTitle:@"优先级高" forState:UIControlStateNormal];
        
    }
    if (_model.priority==1) {
        [self.prioritybutton setBackgroundColor:[UIColor xm_colorFromRGB:0xfe962c]];
        [self.prioritybutton setTitle:@"优先级普通" forState:UIControlStateNormal];

    }
    if (_model.priority==0) {
//        [self.prioritybutton setBackgroundColor:[UIColor blueColor]];
        [self.prioritybutton setBackgroundColor:[UIColor xm_colorFromRGB:0xfe962c]];
        [self.prioritybutton setTitle:@"优先级普通" forState:UIControlStateNormal];

    }
    if (_model.executeState==0) {
        self.souceLabel.text=@"未完成";
    }
    if (_model.executeState==1) {
        self.souceLabel.text=@"已完成";
    }
    if (_model.executeState==2) {
        self.souceLabel.text=@"已拒绝";
        if ([_model.count isEqualToString:@"2"]) {
            self.souceLabel.text=@"未完成";
        }
    }
    if (_model.executeState==3) {
        self.souceLabel.text=@"待审批";
    }
//    self.tagLabel.text = _model.Tag;
//    self.timeLabel.text = [XMTool  timeIntervalFromLastTime:_model.UpdateTime];
//
//    self.souceLabel.text = _model.Souce;
//    if ([_model.Tag isEqualToString:@"热门"]) {
//        self.tagLabel.hidden = NO;
//
//        self.tagLabel.backgroundColor = [UIColor xm_colorFromRGB:0xff0000 alpha:0.04];
//        self.tagLabel.textColor = [UIColor xm_colorFromRGB:0xFF6666];
//    }else if ([_model.Tag isEqualToString:@"推荐"]){
//        self.tagLabel.hidden = NO;
//
//        self.tagLabel.backgroundColor = [UIColor xm_colorFromRGB:0x212832 alpha:0.04];
//        self.tagLabel.textColor = [UIColor xm_colorFromRGB:0x1B88EE];
//    }else{
//        self.tagLabel.hidden = YES;
//    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
    [self.prioritybutton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self).offset(0);
        make.width.equalTo(@70);
        make.height.equalTo(@20);

    }];
    [self.souceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.prioritybutton.mas_bottom).offset(35);
    }];
    
    [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self);
        make.right.mas_equalTo(self).offset(-10);
    }];
    
}
-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
}


@end
